/**
 * 
 */
package com.wordpress.sharebyblog.world.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;

import com.wordpress.sharebyblog.world.domain.CountryLanguage;

/**
 * @author Bharat Mehta
 *
 */
public class CountryLanguageDaoImpl extends NamedParameterJdbcDaoSupport implements CountryLanguageDao{

	
	private static final String FIND_LANGUAGE_BY_COUNTRYCODE = "select countrycode,language,isOfficial,percentage from countrylanguage where countryCode =:countryCode";
	private static final String FIND_LANGUAGE_BY_COUNTRYCODE_AND_STATUS = FIND_LANGUAGE_BY_COUNTRYCODE + " and isOfficial=:isOfficial";
	
	@Override
	public List<CountryLanguage> findLanguageByCountry(String countryCode) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("countryCode", countryCode);
		return getNamedParameterJdbcTemplate().query(FIND_LANGUAGE_BY_COUNTRYCODE, map, 
				new BeanPropertyRowMapper<CountryLanguage>(CountryLanguage.class));
	
	}

	@Override
	public List<CountryLanguage> findLanguageByCountry(String countryCode,
			boolean isOfficial) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("countryCode", countryCode);
		map.put("isOfficial", isOfficial?"T":"F");
		return getNamedParameterJdbcTemplate().query(FIND_LANGUAGE_BY_COUNTRYCODE_AND_STATUS, map, 
				new BeanPropertyRowMapper<CountryLanguage>(CountryLanguage.class));
	}

}
